part of '../widgets.dart';

/// [VanTag]属性常量
const kVanTagPadding = VanCssKey._raw('--van-tag-padding');
const kVanTagTextColor = VanCssKey._raw('--van-tag-text-color');
const kVanTagFontSize = VanCssKey._raw('--van-tag-font-size');
const kVanTagRadius = VanCssKey._raw('--van-tag-radius');
const kVanTagLineHeight = VanCssKey._raw('--van-tag-line-height');
const kVanTagMediumPadding = VanCssKey._raw('--van-tag-medium-padding');
const kVanTagLargePadding = VanCssKey._raw('--van-tag-large-padding');
const kVanTagLargeRadius = VanCssKey._raw('--van-tag-large-radius');
const kVanTagLargeFontSize = VanCssKey._raw('--van-tag-large-font-size');
const kVanTagRoundRadius = VanCssKey._raw('--van-tag-round-radius');
const kVanTagDangerColor = VanCssKey._raw('--van-tag-danger-color');
const kVanTagPrimaryColor = VanCssKey._raw('--van-tag-primary-color');
const kVanTagSuccessColor = VanCssKey._raw('--van-tag-success-color');
const kVanTagWarningColor = VanCssKey._raw('--van-tag-warning-color');
const kVanTagDefaultColor = VanCssKey._raw('--van-tag-default-color');
const kVanTagPlainBackground = VanCssKey._raw('--van-tag-plain-background');


/// [VanTag]主题类
@immutable
class VanTagTheme extends VanProvider<VanTagThemeData> with VanProvide {
  const VanTagTheme({super.key, required super.child, required super.provide});

  static VanTagThemeData of(BuildContext context) => VanProvider.of<VanTagTheme>(context)?.provide ?? VanTheme.of(context).tagTheme;
  static const _prefix = "--van-tag-";
  static bool support(VanCssKey key) => key.key.startsWith(_prefix);

  static dynamic get<T>(BuildContext context, {required VanCssKey key, T? defaultValue}) {
    final VanTagThemeData tagTheme = VanTagTheme.of(context);
    if (kVanTagPadding == key) return tagTheme.padding.get(context);
    if (kVanTagTextColor == key) return tagTheme.textColor.get(context);
    if (kVanTagFontSize == key) return tagTheme.fontSize.get(context);
    if (kVanTagRadius == key) return tagTheme.radius.get(context);
    if (kVanTagLineHeight == key) return tagTheme.lineHeight.get(context);
    if (kVanTagMediumPadding == key) return tagTheme.mediumPadding.get(context);
    if (kVanTagLargePadding == key) return tagTheme.largePadding.get(context);
    if (kVanTagLargeRadius == key) return tagTheme.largeRadius.get(context);
    if (kVanTagLargeFontSize == key) return tagTheme.largeFontSize.get(context);
    if (kVanTagRoundRadius == key) return tagTheme.roundRadius.get(context);
    if (kVanTagDangerColor == key) return tagTheme.dangerColor.get(context);
    if (kVanTagPrimaryColor == key) return tagTheme.primaryColor.get(context);
    if (kVanTagSuccessColor == key) return tagTheme.successColor.get(context);
    if (kVanTagWarningColor == key) return tagTheme.warningColor.get(context);
    if (kVanTagDefaultColor == key) return tagTheme.defaultColor.get(context);
    if (kVanTagPlainBackground == key) return tagTheme.plainBackground.get(context);
    return null;
  }
}

/// [VanTag]主题数据类
@immutable
class VanTagThemeData with VanProvide {
  final VanCss<EdgeInsets> padding;
  final VanCss<Color> textColor;
  final VanCss<double> fontSize;
  final VanCss<BorderRadius> radius;
  final VanCss<double> lineHeight;
  final VanCss<EdgeInsets> mediumPadding;
  final VanCss<EdgeInsets> largePadding;
  final VanCss<BorderRadius> largeRadius;
  final VanCss<double> largeFontSize;
  final VanCss<BorderRadius> roundRadius;
  final VanCss<Color> dangerColor;
  final VanCss<Color> primaryColor;
  final VanCss<Color> successColor;
  final VanCss<Color> warningColor;
  final VanCss<Color> defaultColor;
  final VanCss<VanBgColor> plainBackground;

  /// 构造器
  const VanTagThemeData.raw({
    required this.padding,
    required this.textColor,
    required this.fontSize,
    required this.radius,
    required this.lineHeight,
    required this.mediumPadding,
    required this.largePadding,
    required this.largeRadius,
    required this.largeFontSize,
    required this.roundRadius,
    required this.dangerColor,
    required this.primaryColor,
    required this.successColor,
    required this.warningColor,
    required this.defaultColor,
    required this.plainBackground,
  });

  /// 拷贝
  VanTagThemeData copyFrom({
    VanCss<EdgeInsets>? padding,
    VanCss<Color>? textColor,
    VanCss<double>? fontSize,
    VanCss<BorderRadius>? radius,
    VanCss<double>? lineHeight,
    VanCss<EdgeInsets>? mediumPadding,
    VanCss<EdgeInsets>? largePadding,
    VanCss<BorderRadius>? largeRadius,
    VanCss<double>? largeFontSize,
    VanCss<BorderRadius>? roundRadius,
    VanCss<Color>? dangerColor,
    VanCss<Color>? primaryColor,
    VanCss<Color>? successColor,
    VanCss<Color>? warningColor,
    VanCss<Color>? defaultColor,
    VanCss<VanBgColor>? plainBackground,
  }) {
    return VanTagThemeData.raw(
      padding: padding ?? this.padding,
      textColor: textColor ?? this.textColor,
      fontSize: fontSize ?? this.fontSize,
      radius: radius ?? this.radius,
      lineHeight: lineHeight ?? this.lineHeight,
      mediumPadding: mediumPadding ?? this.mediumPadding,
      largePadding: largePadding ?? this.largePadding,
      largeRadius: largeRadius ?? this.largeRadius,
      largeFontSize: largeFontSize ?? this.largeFontSize,
      roundRadius: roundRadius ?? this.roundRadius,
      dangerColor: dangerColor ?? this.dangerColor,
      primaryColor: primaryColor ?? this.primaryColor,
      successColor: successColor ?? this.successColor,
      warningColor: warningColor ?? this.warningColor,
      defaultColor: defaultColor ?? this.defaultColor,
      plainBackground: plainBackground ?? this.plainBackground,
    );
  }

  /// 反序列化
  static VanTagThemeData fromJson(Map<String, dynamic> json) {
    return VanTagThemeData.raw(
      padding: VanCss(json[kVanTagPadding.key]),
      textColor: VanCss(json[kVanTagTextColor.key]),
      fontSize: VanCss(json[kVanTagFontSize.key]),
      radius: VanCss(json[kVanTagRadius.key]),
      lineHeight: VanCss(json[kVanTagLineHeight.key]),
      mediumPadding: VanCss(json[kVanTagMediumPadding.key]),
      largePadding: VanCss(json[kVanTagLargePadding.key]),
      largeRadius: VanCss(json[kVanTagLargeRadius.key]),
      largeFontSize: VanCss(json[kVanTagLargeFontSize.key]),
      roundRadius: VanCss(json[kVanTagRoundRadius.key]),
      dangerColor: VanCss(json[kVanTagDangerColor.key]),
      primaryColor: VanCss(json[kVanTagPrimaryColor.key]),
      successColor: VanCss(json[kVanTagSuccessColor.key]),
      warningColor: VanCss(json[kVanTagWarningColor.key]),
      defaultColor: VanCss(json[kVanTagDefaultColor.key]),
      plainBackground: VanCss(json[kVanTagPlainBackground.key]),
    );
  }

}

/// [VanTag]样式
@immutable
class VanTagStyle with VanProvide {
  static of(BuildContext context) => VanProvider.of<VanTagStyle>(context);

  final EdgeInsets? padding;
  final Color? textColor;
  final double? fontSize;
  final Border? border;
  final BorderRadius? radius;
  final double? lineHeight;
  final VanBgColor? background;

  VanTagStyle({
    this.padding,
    this.textColor,
    this.fontSize,
    this.border,
    this.radius,
    this.lineHeight,
    this.background,
  });

  bool get isNonNull {
    if (padding == null) return false;
    if (textColor == null) return false;
    if (fontSize == null) return false;
    if (radius == null) return false;
    if (lineHeight == null) return false;
    if (background == null) return false;
    return true;
  }

  VanTagStyle copyFrom({
    EdgeInsets? padding,
    Color? textColor,
    double? fontSize,
    Border? border,
    BorderRadius? radius,
    double? lineHeight,
    Color? color,
    VanBgColor? background,
  }) {
    return VanTagStyle(
      padding: padding ?? this.padding,
      textColor: textColor ?? this.textColor,
      fontSize: fontSize ?? this.fontSize,
      border: border?? this.border,
      radius: radius ?? this.radius,
      lineHeight: lineHeight ?? this.lineHeight,
      background: background ?? this.background,
    );
  }
}